//
//  MYGCloudDiskDoucmentSheet.swift
//  MYDoctor
//
//  Created by Denny on 2024/4/22.
//

import UIKit

class MYGCloudDiskDoucmentSheet: UIView {
    @IBOutlet weak var btnWidth: NSLayoutConstraint!
    @IBOutlet weak var left1: NSLayoutConstraint!
    var fileModel = MYCloudDiskContentModel()
    var tapRenameCompletion:(()->Void)?
    var tapShareCompletion:(()->Void)?
    var tapDismissCompletion:(()->Void)?
    override func awakeFromNib() {
        super.awakeFromNib()
        let margin = max(0, (screenWidth - 70 * 4)/5)
        self.left1.constant = margin
    }

    @IBAction func tapAction(_ sender: UIButton) {
        if sender.tag == 50 {
            //下载
            MYGDownloadManager.shared.addDownloadTask(self.fileModel)
            if let c = tapDismissCompletion {
                c()
            }
        }else if sender.tag == 51 {
            //分享
            if let c = tapShareCompletion {
                c()
            }
        }else if sender.tag == 52 {
            //重命名
            if let c = tapRenameCompletion {
                c()
            }
            
        }else if sender.tag == 53 {
            
            //删除
            MYGLoading.show()
            MYGNetwork<MYGMeAPI,MYGEmptyModel>.request(target: .netdiskLogDelete(id: fileModel.id)) { item in
                NotificationCenter.default.post(name: NSNotification.Name("MYCloudDiskViewController_configDataSource"), object: nil)
                MYGLoading.hide()
            } failed: { _, error in
                MYGLoading.hide()
            }
            if let c = tapDismissCompletion {
                c()
            }
        }
    }
}
